package hczc.longcai.com.hccrowdfunding.home.second_invest.activities;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.activity.BaseActivity;

public class WayofPayActivity extends BaseActivity implements View.OnClickListener {

    private List<ImageView> imageViews;
    private ImageView balance;
    private ImageView zfb;
    private ImageView wx;
    private Button pay;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wayof_pay);

        initViews();
    }

    private void initViews() {

        imageViews = new ArrayList<>();

        findViewById(R.id.head_back).setOnClickListener(this);
        ((TextView) findViewById(R.id.head_title)).setText("选择支付方式");

        balance = ((ImageView) findViewById(R.id.way_of_pay_balance_choose));
        balance.setOnClickListener(this);
        imageViews.add(balance);
        zfb = ((ImageView) findViewById(R.id.way_of_pay_zfb_choose));
        zfb.setOnClickListener(this);
        imageViews.add(zfb);
        wx = ((ImageView) findViewById(R.id.way_of_pay_wx_choose));
        wx.setOnClickListener(this);
        imageViews.add(wx);

        pay = ((Button) findViewById(R.id.way_of_pay_button));
        pay.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        int size = imageViews.size();
        switch (id){
            /**
             * 回退按钮
             */
            case R.id.head_back:
                finish();
                break;
            /**
             * 使用余额支付
             */
            case R.id.way_of_pay_balance_choose:
                for(int i = 0; i < size; i++){
                    imageViews.get(i).setSelected(false);
                }
                balance.setSelected(true);
                break;
            /**
             * 使用支付宝支付
             */
            case R.id.way_of_pay_zfb_choose:
                for(int i = 0; i < size; i++){
                    imageViews.get(i).setSelected(false);
                }
                zfb.setSelected(true);
                break;
            /**
             * 使用微信支付
             */
            case R.id.way_of_pay_wx_choose:
                for(int i = 0; i < size; i++){
                    imageViews.get(i).setSelected(false);
                }
                wx.setSelected(true);
                break;
            /**
             * 支付按钮
             */
            case R.id.way_of_pay_button:
                Toast.makeText(WayofPayActivity.this,"支付成功！",Toast.LENGTH_SHORT).show();
                finish();
                break;
        }
    }
}
